module "vmwaretest" {
  #本地路径可以使用同一项目中的子模块，无需下载相关代码即可使用。但每个云模板都要单独维护source源。
  # source                     = "./modules/vmware"
  #主推方式。将source 参数值设置为一个Git仓库源（仓库权限为公开）。支持SSH和HTTPS协议克隆仓库，无需重复维护source源
  source = "./modules/terraform-vmware-vm"
#  version = "2.0.2"
  idc_code                   = "Datacenter-DEV"
  datastore                  = "Datastore"
  disk_label                 = ["disk0"]
  scsi_controller            = 0
  data_disk_scsi_controller  = []
  data_disk_label            = []
  data_disk_size_gb          = ["120"]
  thin_provisioned           = null
  eagerly_scrub              = null
  domain                     = "test.internal"
  instance_name              = "example-0816"
  image                      = "xiaohei-test"
  ips                        = "10.0.200.209"
  dns_server                 = ["10.0.0.1"]
  netmask                    = "16"
  gateway                    = "10.0.0.1"
  cpu                        = 8
  memory                     = 12288
  network                    = "VM Network"
  resource_pool              = "xiaohei-test"
  instance_number            = 1
}

module "vmwaretest1" {
  #本地路径可以使用同一项目中的子模块，无需下载相关代码即可使用。但每个云模板都要单独维护source源。
  # source                     = "./modules/vmware"
  #主推方式。将source 参数值设置为一个Git仓库源（仓库权限为公开）。支持SSH和HTTPS协议克隆仓库，无需重复维护source源
  source = "./modules/terraform-vmware-vm"
#  version = "2.0.2"
  idc_code                   = var.idc_code
  datastore                  = var.datastore
  disk_label                 = var.disk_label
  scsi_controller            = var.scsi_controller
  data_disk_scsi_controller  = var.data_disk_scsi_controller
  data_disk_label            = var.data_disk_label
  data_disk_size_gb          = var.data_disk_size_gb
  thin_provisioned           = var.thin_provisioned
  eagerly_scrub              = var.eagerly_scrub
  domain                     = var.domain
  instance_name              = var.instance_name
  image                      = var.image
  ips                        = var.ips
  dns_server                 = var.dns_server
  netmask                    = var.netmask
  gateway                    = var.gateway
  cpu                        = var.cpu
  memory                     = var.memory
  network                    = var.network
  resource_pool              = var.resource_pool
  instance_number            = var.instance_number
}

resource "ansible_host" "qfusion_master" {
  count = 1
  // 配置机器的 hostname，一般配置为计算资源的 public_ip (或 private_ip)
  inventory_hostname = module.vmwaretest.vm_ip_address[count.index]
  // 配置机器所属分组
  groups             = list(var.inventory)
  // 传给 ansible 的 vars，可在 playbook 文件中引用
  vars = {
    vm_ip_address_master = module.vmwaretest.vm_ip_address[count.index]
    vm_ip_address_salve1 = module.vmwaretest1.vm_ip_address[0]
    vm_ip_address_salve2 = module.vmwaretest1.vm_ip_address[1]
    ansible_ssh_pass = var.ansible_ssh_pass
    wait_connection_timeout = 600
  }
}

resource "ansible_host" "qfusion" {
  count = var.instance_number
  // 配置机器的 hostname，一般配置为计算资源的 public_ip (或 private_ip)
  inventory_hostname = module.vmwaretest1.vm_ip_address[count.index]
  // 配置机器所属分组
  groups             = list(var.inventory)
  // 传给 ansible 的 vars，可在 playbook 文件中引用
  vars = {
    vm_ip_address_master = module.vmwaretest.vm_ip_address[0]
    vm_ip_address_salve1 = module.vmwaretest1.vm_ip_address[0]
    vm_ip_address_salve2 = module.vmwaretest1.vm_ip_address[1]
    ansible_ssh_pass = var.ansible_ssh_pass
    wait_connection_timeout = 600
  }
}
